home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / U-Z / VideoToolBox Folder / Utilities / GrabDrivers / GrabSlotDrivers.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-01  |  3.6 KB  |  117 lines  |  [TEXT/KAHL]

  1. /* GrabSlotDrivers.c
  2. Repeatedly calls the Slot Manager to get every slot driver and puts each in its
  3. own file. These files can then be perused with the ResEdit CODE viewer. 
  4.  
  5. The ResEdit CODE viewer is a public domain file, for use with ResEdit, distributed by:
  6. Ira L. Ruben
  7. Apple Computer, Inc.
  8. 20525 Mariani Ave., MS: 37-A
  9. Cupertino, Ca. 95014
  10. Ira@Apple.Com
  11.  
  12. Note that GrabSlotDrivers gets the driver directly from the card's configuration
  13. ROM, whereas it is possible that your run-time System is actually superceding
  14. that by a later version of the driver loaded from the System file or by an INIT.
  15. If you want the active version of the driver it would be best to get it from the
  16. device manager, which is what GrabVideoDrivers.c does, though it skips non-video
  17. devices.
  18.  
  19. HISTORY:
  20. 2/89 dgp Wrote it as "video hacker II" using THINK C 3.
  21. 1/3/93 dgp updated it to THINK C 5 and renamed it GrabSlotDrivers.c
  22. */
  23. #include "VideoToolbox.h"
  24. #include <Errors.h>
  25. #include <Resources.h>
  26. #include <Traps.h>
  27. typedef struct {
  28.     short flags;
  29.     short blanks[3];
  30.     short open;
  31.     short prime;
  32.     short control;
  33.     short status;
  34.     short close;
  35.     Str255 name;
  36. } VideoDriver;
  37. void AddResourceToFile(unsigned char *filename,unsigned char *name,ResType type,int id,Handle handle);
  38. void GrabSlotDrivers(void);
  39.  
  40. void main(void)
  41. {
  42.     Require(0);
  43.     MaximizeConsoleHeight();
  44.     printf("Welcome to GrabSlotDrivers.\n"
  45.     "This programs copies all drivers from your slot devices.\n"
  46.     "Note that this gets the driver from the card's configuration ROM, whereas\n"
  47.     "it is possible that your run-time System is actually superceding\n"
  48.     "that by a later version of the driver loaded from the System file or by an INIT.\n");
  49.     GrabSlotDrivers();
  50. }
  51.  
  52. void GrabSlotDrivers(void)
  53. {
  54.     SpBlock mySpBlock;
  55.     SEBlock mySEBlock;
  56.     unsigned char name[256],filename[32];
  57.     OSErr error;
  58.     Ptr *handle;
  59.     int i;
  60.     int version;
  61.     VideoDriver *videoDriverPtr;
  62.     unsigned char *bytePtr;
  63.  
  64.     mySpBlock.spsExecPBlk = (Ptr) &mySEBlock;
  65.     mySpBlock.spSlot = 0;
  66.     mySpBlock.spID = 0;
  67.     mySpBlock.spExtDev = 0;
  68.  
  69.     while(1){
  70.         error = SNextSRsrc(&mySpBlock);
  71.         if(error==smNoMoresRsrcs) break;
  72.         if(error){
  73.             printf("SNextSRsrc error %d\n",error);
  74.             break;
  75.         }
  76.         mySpBlock.spResult = (unsigned long) &name;
  77.         error = SReadDrvrName(&mySpBlock);
  78.         printf("SReadDrvrName=%#s\n",name);    
  79.         printf("spSlot=%d,spID=%d,spExtDev=%d"
  80.             ,mySpBlock.spSlot,mySpBlock.spID,mySpBlock.spExtDev);
  81.         printf(",spCategory=%d,spCType=%d,spDrvrSW=%d,spDrvrHW=%d,spRefNum=%d\n"
  82.             ,mySpBlock.spCategory,mySpBlock.spCType,mySpBlock.spDrvrSW
  83.             ,mySpBlock.spDrvrHW,mySpBlock.spRefNum);
  84.  
  85.         /* filename must be truncated to 31 characters */
  86.         for (i=0;i<32;i++) filename[i]=name[i];
  87.         if((unsigned char)filename[0] > 31) filename[0]=31;
  88.         // Replace leading "." by "-" since the Mac filing system 
  89.         // is confused by filenames beginning with ".".
  90.         if(filename[1]=='.')filename[1]='-';
  91.         
  92.         /* get handle to desired driver resource */
  93.         error = SGetDriver(&mySpBlock);
  94.         if(!error) {
  95.             handle = (Ptr *) mySpBlock.spResult;
  96.     
  97.             // Is this a video driver?
  98.             videoDriverPtr=*(VideoDriver **)handle;
  99.             if(EqualString(name,videoDriverPtr->name,1,1)){
  100.                 // Probably is a video driver. The version number of a video driver 
  101.                 // is the first word-aligned word after the name string.
  102.                 bytePtr= videoDriverPtr->name;
  103.                 bytePtr += 1+bytePtr[0];    /* go to end of Pascal string */
  104.                 bytePtr = (unsigned char *)((long)(bytePtr+1) & ~1);    // round up to word boundary
  105.                 version = *(short *)bytePtr;
  106.             } else version=rand();
  107.         
  108.             AddResourceToFile(filename,name,'DRVR',version,handle);
  109.             printf("Driver copied to ā€œ%#sā€ file, using %d as id.\n",filename,version);
  110.             DisposHandle(handle);
  111.         }
  112.         else printf("No driver.\n");
  113.         printf("\n");
  114.     }
  115. }
  116.  
  117.